﻿using GalaSoft.MvvmLight;
using System;

namespace SimpleChat.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class CreateServerViewModel : ViewModelBase
    {
        #region ServerName
        /// <summary>
        /// The <see cref="ServerName" /> property's name.
        /// </summary>
        public const string ServerNamePropertyName = "ServerName";

        private string _storeServerName = "";

        /// <summary>
        /// Gets the ServerName property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string ServerName
        {
            get
            {
                return _storeServerName;
            }

            set
            {
                if (_storeServerName == value)
                {
                    return;
                }

                var oldValue = _storeServerName;
                _storeServerName = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(ServerNamePropertyName);
            }
        }
        #endregion

        #region ServerPassword
        /// <summary>
        /// The <see cref="ServerPassword" /> property's name.
        /// </summary>
        public const string ServerPasswordPropertyName = "ServerPassword";

        private string _storeServerPassword = "";

        /// <summary>
        /// Gets the ServerPassword property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string ServerPassword
        {
            get
            {
                return _storeServerPassword;
            }

            set
            {
                if (_storeServerPassword == value)
                {
                    return;
                }

                var oldValue = _storeServerPassword;
                _storeServerPassword = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(ServerPasswordPropertyName);
            }
        }
        #endregion

        #region Username
        /// <summary>
        /// The <see cref="Username" /> property's name.
        /// </summary>
        public const string UsernamePropertyName = "Username";

        private string _storeUsername = "";

        /// <summary>
        /// Gets the Username property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string Username
        {
            get
            {
                return _storeUsername;
            }

            set
            {
                if (_storeUsername == value)
                {
                    return;
                }

                var oldValue = _storeUsername;
                _storeUsername = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(UsernamePropertyName);
            }
        }
        #endregion
        
        /// <summary>
        /// Initializes a new instance of the CreateServerViewModel class.
        /// </summary>
        public CreateServerViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                ServerName = "SimpleChat NetAccess V3 Server";
            }
        }

        public override void Cleanup()
        {
            // Clean own resources if needed

            base.Cleanup();
        }
    }
}